package com.zzh.fullscreen;

import test.Draw;

import java.awt.*;

public class Flyer {
    protected int x;
    protected int y;
    protected int velx;
    protected int vely;
    protected int speed = 0;
    protected int width;
    protected int height;
    /**
     * 碰撞矩形
     */
    protected int cx, cy, cwidth, cheight;
    // protected BufferedImage image;
    public final static int UP = -1;
    public final static int DOWN = 1;

    public Flyer() {
    }

    public Flyer(int x, int y, int vx, int vy) {
        this.x = x;
        this.y = y;
        this.velx = vx;
        this.vely = vy;
        cx = x;
        cy = y;
        cwidth = width;
        cheight = height;
    }

    public Flyer(int x, int y, int vx, int vy,int width,int height) {
        this.x = x;
        this.y = y;
        this.velx = vx;
        this.vely = vy;
        this.cx = x;
        this.cy = y;
        this.width = this.cwidth = width;
        this.height = this.cheight = height;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public Flyer setX(int x) {
        this.x = x;
        return this;
    }

    public Flyer setY(int y) {
        this.y = y;
        return this;
    }
//	public int getCenterX() {
//		return x + width / 2;
//	}
//
//	public int getCenterY() {
//		return y + height / 2;
//	}

    public int getWidth() {
        return width;
    }

    public int getHeight() {
        return height;
    }

    public void updataXY() {
        x += velx;
        y += vely;
        cx += velx;
        cy += vely;
    }

    public boolean outOfbounds() {
        if (x + width <= 0 || x >= Draw.screenWidth) {
            return true;
        }
        if (y + height <= 0 || y >= Draw.screenHeight) {
            return true;
        }
        return false;
    }

    public boolean intersectTo(Flyer a) {
        return (this.cx < a.cx + a.cwidth && this.cy < a.cy + a.cheight
                && this.cx + this.cwidth > a.cx && this.cy + this.cheight > a.cy);
    }
    /**绘制碰撞矩形*/
    public void drawCollide(Graphics g){
        g.drawRect(this.cx, this.cy, this.cwidth, this.cheight);
    }
}
